use crate::id::{QueueId, ReaderId};

use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("malformed queue ID")]
    QueueIdMalformed,

    #[error("malformed reader ID")]
    ReaderIdMalformed,

    #[error("unknown queue: {0}")]
    UnknownQueue(QueueId),

    #[error("reader {0} not in queue")]
    ReaderNotPresent(ReaderId),

    #[error("queried invalid range (min {0}, max {1})")]
    InvalidRange(u64, u64),

    #[error("sanity check: {0}")]
    Sanity(#[from] SanityError),

    #[error("codec: {0}")]
    Codec(#[from] aspect_codec::CodecError),

    #[error("not yet implemented")]
    Unimplemented,

    #[error("{0}")]
    Other(String),
}

#[derive(Debug, Error)]
pub enum SanityError {
    #[error("reader list unsorted")]
    ReadersUnsorted,

    #[error("readers mismatch pos len (readers {0}, poses {1})")]
    ReaderVecsMismatch(usize, usize),

    #[error("next and tail idxs invalid (next {0}, tail {0}")]
    NextTailOob(u64, u64),

    #[error("reader {1} out of bounds (at {0}, tail {2}, next {3}")]
    PositionOob(u64, ReaderId, u64, u64),
}
